#include <string.h>
#include <SDL_keyboard.h>
#include "Keyboard.h"


static Uint8 prev[Keyboard::kKeyCount] = { 0 };
static Uint8 curr[Keyboard::kKeyCount] = { 0 };


bool Keyboard::IsKeyDown(Keys key)
{
	return (key < kKeyCount) && curr[key];
}

bool Keyboard::IsKeyUp(Keys key)
{
	return (key < kKeyCount) && !curr[key];
}

bool Keyboard::WasKeyPressed(Keys key)
{
	return (key < kKeyCount) && curr[key] && !prev[key];
}

bool Keyboard::WasKeyReleased(Keys key)
{
	return (key < kKeyCount) && !curr[key] && prev[key];
}

void Keyboard::Update()
{
	int count;
	Uint8* state = SDL_GetKeyboardState(&count);
	memcpy(prev, curr, sizeof(curr));
	memcpy(curr, state, count*sizeof(Uint8));
}
